/*
 * SymulatorWindyView.java
 */

package symulatorwindy;

import java.awt.ScrollPane;
import java.io.IOException;
import java.util.logging.LogRecord;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import symulatorwindy.animation.ElevatorMovement;
import symulatorwindy.logic.NajblizszeWezwanie;
import symulatorwindy.logic.Parametry;
import symulatorwindy.logic.Pasazer;
import symulatorwindy.logic.Pietro;
import symulatorwindy.logic.Winda;

/**
 * The application's main frame.
 */
public class SymulatorWindyView extends FrameView {

    public static final Logger LOG = Logger.getLogger("Winda");

    public static final int FLOOR_COUNT = 11;
    public static final int FLOOR_TIME = 0;
    public static final int ENTER_TIME = 0;
    private ElevatorMovement em;
    Winda w = new Winda();
    private int floor_count =FLOOR_COUNT;
    private int czasWeWy = 1000;
    private int czasJazdyPrzezPietro = 1000;
    private int passangers = 0;

    private ButtonGroup buttonGroup;
    private DefaultListModel passengerListModel = new DefaultListModel();

    private ResourceMap resMap = org.jdesktop.application.Application.getInstance(symulatorwindy.SymulatorWindyApp.class).getContext().getResourceMap(SymulatorWindyView.class);
    public SymulatorWindyView(SingleFrameApplication app) {
        super(app);
        
        initComponents();
        buttonGroup = new ButtonGroup();
        buttonGroup.add(algRadioButton1);
        buttonGroup.add(algRadioButton2);
        Refresh r = new Refresh(elevatorView);
        new Thread(r).start();
        
        drawAnimation();
        //setupDemoPassangersList();
//        em.enableSecondElevator();
//        w.SetDwieWindy();
        //newAnimation(this.floor_count);
        enterTimeSpinner.setValue(czasWeWy);
        floorTimeSpinner.setValue(czasJazdyPrzezPietro);
        speedSlider.setValue(1);
        WindowHandler wh = new WindowHandler(logArea);
        LOG.setLevel(Level.ALL);
        LOG.addHandler(wh);
        try {
            FileHandler fh = new FileHandler("log.txt", true);
            fh.setFormatter(new Formatter(){
                @Override
                public String format(LogRecord lr) {
                    return lr.getMessage()+"\n";
                }
                
            });

            LOG.addHandler(fh);
        } catch (IOException ex) {
            Logger.getLogger(SymulatorWindyView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(SymulatorWindyView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
//
//    private void setupDemoPassangersList(){
//        int n = 1;
//        Winda temp = new Winda();
//        temp.WczytajPasazerow("DemoDane.txt");
//        List<Pasazer> tmp = temp.getPasazerowieCollection();
//        for(int i=0;i<tmp.size();i++){
//            passengerListModel.addElement(n+". "+tmp.get(i).getStart()+" => "+tmp.get(i).getStop());
//            n++;
//        }
//        this.passangers = n;
//    }

    private void cleanPassangersList(){
        this.passangers = 0;
        passengerListModel.removeAllElements();
    }

    private void addPassangerToList(int start, int stop){
        int mul = Integer.parseInt(multiplySpinner.getValue().toString());
        if(mul>0)
            for(int i = 0;i<mul;i++){
                this.passangers++;
               passengerListModel.addElement(this.passangers+". "+start+" => "+stop);
            }
        else{
            this.passangers++;
            passengerListModel.addElement(this.passangers+". "+start+" => "+stop);
        }
    }

    private void removeLastPassangerFromList(){
        passengerList.remove(passengerListModel.getSize()-1);
        this.passangers--;
    }

//    private void setupAnimation(){
//        int []passengersUp = new int[this.floor_count];
//        int[] passengersDown = new int[floor_count];
//        ArrayList<Pietro> temp = (ArrayList) this.w.GetTrasa();
//        ArrayList<Pietro> temp2 = (ArrayList) this.w.GetTrasaDwa();
//        em.stop();
//        for(Pietro p : temp){
//            int floor = p.numerPietra;
//            int upCount = 0;
//            int downCount = 0;
//            for(Pasazer pas : p.pasazerowieWsiadający){
//                if(pas.naGore())
//                    upCount++;
//                else
//                    downCount++;
//            }
//            passengersUp[floor] += upCount;
//            passengersDown[floor]+=downCount;
//        }
//
//        if(temp2!=null){
//            for(Pietro p : temp2){
//                int floor = p.numerPietra;
//            int upCount = 0;
//            int downCount = 0;
//            for(Pasazer pas : p.pasazerowieWsiadający){
//                if(pas.naGore())
//                    upCount++;
//                else
//                    downCount++;
//            }
//            passengersUp[floor] += upCount;
//            passengersDown[floor]+=downCount;
//            }
//        }
//        em.setPassangersOnFloorsUp(passengersUp);
//        em.setPassangersOnFloorsDown(passengersDown);
//
//    }

    private void showPassengersOnFloors(){
        int []passengersUp = new int[this.floor_count];
        int[] passengersDown = new int[floor_count];
        em.stop();
        for(Pasazer pas : w.getPasazerowieCollection()){
            if(pas.naGore()){
                passengersUp[pas.getStart()]+=1;
            }else{
                passengersDown[pas.getStart()]+=1;
            }
        }
        em.setPassangersOnFloorsUp(passengersUp);
        em.setPassangersOnFloorsDown(passengersDown);
        elevatorView.repaint();
    }

    private void goToPietro(){
        em.setRoute((ArrayList) w.GetTrasa(), 1);
        if (twoElevatorsCheckbox.isSelected())
            em.setRoute((ArrayList) w.GetTrasaDwa(), 2);
        em.setEnterExitTime(czasWeWy);
        em.run();
        /*for(int i=0;i<this.w.GetTrasa().size();i++){
            this.em.setPietro(this.w.GetTrasa().get(i));
            Thread t = new Thread(em);
            t.start();
        }*/
    }

    private void drawAnimation(){
        this.em = new ElevatorMovement(this.floor_count);
        em.setStartFloors(0, floor_count-1);
        elevatorView.add(this.em.getElevatorAnimation());
    }

    private void newAnimation(int floor_count){
        elevatorView.remove(this.em.getElevatorAnimation());
        this.em.setFloorsCount(floor_count);
        elevatorView.add(this.em.getElevatorAnimation());
        elevatorView.doLayout();
        this.elevatorView.repaint();
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = SymulatorWindyApp.getApplication().getMainFrame();
            aboutBox = new SymulatorWindyAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        SymulatorWindyApp.getApplication().show(aboutBox);
    }

    private void toggleComponents(boolean enable){
        algRadioButton1.setEnabled(enable);
        algRadioButton2.setEnabled(enable);
        floorCountSpinner.setEnabled(enable);
        twoElevatorsCheckbox.setEnabled(enable);
        floorTimeSpinner.setEnabled(enable);
        enterTimeSpinner.setEnabled(enable);
        startButton.setEnabled(enable);
    }
    private void loadFile(String path){
        w.SetNowyProjekt();
        w.WczytajPasazerow(path);
        w.SetIloscPieter(floor_count);
        w.SetCzasJazdyPietro(this.czasJazdyPrzezPietro);
        w.SetCzasWeWyOsoby(czasWeWy);
        if (algRadioButton1.isSelected())
            w.SetGoraDol();
        else
            w.SetNajblizszeWzwanie();
        newAnimation(floor_count);
        int n = 0;
        List<Pasazer> tmp = w.getPasazerowieCollection();
        for(int i=0;i<tmp.size();i++){
            passengerListModel.addElement(n+". "+tmp.get(i).getStart()+" => "+tmp.get(i).getStop());
            n++;
        }
        this.passangers = n;
        //setupDemoPassangersList();
    }

    private void stat(){
         Parametry x = new Parametry(w.GetTrasa(), czasJazdyPrzezPietro, czasWeWy,w.getPasazerowieCollection());
        x.czas_czekania();

        /*jLabel8.setText("Minimalny czas obsługi pasażera: "+"\n"+x.min_obslugi_pasazera);
        jLabel9.setText("Maxymalny czas obsługi pasażera: \n"+x.max_obslugi_pasazera);
        jLabel10.setText("Średni czas obsługi pasażera:   \n"+x.sr_obslugi_pasazera);
        jLabel11.setText("Minimalnz czas czekania:        \n"+x.min_czas_czekania);
        jLabel12.setText("Maxymalny czas czekania:        \n"+x.max_czas_czekania);
        jLabel13.setText("Średni czas czekania:           \n"+x.sr_czas_czekania);*/
        jLabel14.setText(" "+x.min_obslugi_pasazera+" ms.");
        jLabel15.setText(" "+x.max_obslugi_pasazera+" ms.");
        jLabel16.setText(" "+x.sr_obslugi_pasazera+" ms.");
        jLabel17.setText(" "+x.min_czas_czekania+" ms.");
        jLabel18.setText(" "+x.max_czas_czekania+" ms.");
        jLabel19.setText(" "+x.sr_czas_czekania+" ms.");
        label2.setText(" "+x.liczba_pieter );
    }
    private void writeToFile(File file){
        if(w.getPasazerowieCollection().size()>0){
            try {
                BufferedWriter bw = new BufferedWriter(new FileWriter(file));
                for(Pasazer p : w.getPasazerowieCollection()){
                    bw.write(p.getStart()+" "+p.getStop());
                    bw.newLine();
                }
                bw.close();
            } catch (IOException ex) {
                Logger.getLogger(SymulatorWindyView.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    private void newProject(){
                w.SetNowyProjekt();
        w.SetIloscPieter(floor_count);
        w.SetCzasJazdyPietro(this.czasJazdyPrzezPietro);
        w.SetCzasWeWyOsoby(czasWeWy);
        if (algRadioButton1.isSelected())
            w.SetGoraDol();
        else
            w.SetNajblizszeWzwanie();
        newAnimation(floor_count);
        cleanPassangersList();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        floorCountSpinner = new javax.swing.JSpinner();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        startFloorSpinner = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        endFloorSpinner = new javax.swing.JSpinner();
        jLabel4 = new javax.swing.JLabel();
        multiplySpinner = new javax.swing.JSpinner();
        addPassengerButton = new javax.swing.JButton();
        removePassengerButton = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        algRadioButton1 = new javax.swing.JRadioButton();
        algRadioButton2 = new javax.swing.JRadioButton();
        twoElevatorsCheckbox = new javax.swing.JCheckBox(resMap.getString("twoElevatorsCheckbox.text"));
        startButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        passengerList = new javax.swing.JList();
        jPanel4 = new javax.swing.JPanel();
        speedSlider = new javax.swing.JSlider();
        jLabel5 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        floorTimeSpinner = new javax.swing.JSpinner();
        jLabel7 = new javax.swing.JLabel();
        enterTimeSpinner = new javax.swing.JSpinner();
        jPanel6 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        label1 = new java.awt.Label();
        label2 = new java.awt.Label();
        elevatorView = new java.awt.ScrollPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        logArea = new javax.swing.JTextArea();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        menuNewButton = new javax.swing.JMenuItem();
        menuOpenButton = new javax.swing.JMenuItem();
        menuSaveButton = new javax.swing.JMenuItem();
        menuDemoButton = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(825, 551));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(symulatorwindy.SymulatorWindyApp.class).getContext().getResourceMap(SymulatorWindyView.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        floorCountSpinner.setName("floorCountSpinner"); // NOI18N
        floorCountSpinner.setValue(FLOOR_COUNT);
        floorCountSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                floorCountSpinnerStateChanged(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        startFloorSpinner.setName("startFloorSpinner"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        endFloorSpinner.setName("endFloorSpinner"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        multiplySpinner.setName("multiplySpinner"); // NOI18N
        multiplySpinner.setValue(1);

        addPassengerButton.setText(resourceMap.getString("addPassengerButton.text")); // NOI18N
        addPassengerButton.setName("addPassengerButton"); // NOI18N
        addPassengerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPassengerButtonActionPerformed(evt);
            }
        });

        removePassengerButton.setText(resourceMap.getString("removePassengerButton.text")); // NOI18N
        removePassengerButton.setName("removePassengerButton"); // NOI18N
        removePassengerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removePassengerButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(33, 33, 33))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(startFloorSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(endFloorSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(multiplySpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(addPassengerButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(removePassengerButton, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(startFloorSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(endFloorSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(multiplySpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(removePassengerButton)
                    .addComponent(addPassengerButton))
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel3.border.title"))); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        algRadioButton1.setSelected(true);
        algRadioButton1.setText(resourceMap.getString("algRadioButton1.text")); // NOI18N
        algRadioButton1.setName("algRadioButton1"); // NOI18N
        algRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                algRadioButton1ActionPerformed(evt);
            }
        });

        algRadioButton2.setText(resourceMap.getString("algRadioButton2.text")); // NOI18N
        algRadioButton2.setName("algRadioButton2"); // NOI18N
        algRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                algRadioButton2ActionPerformed(evt);
            }
        });

        twoElevatorsCheckbox.setText(resourceMap.getString("twoElevatorsCheckbox.text")); // NOI18N
        twoElevatorsCheckbox.setName("twoElevatorsCheckbox"); // NOI18N
        twoElevatorsCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                twoElevatorsCheckboxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(algRadioButton1)
                    .addComponent(algRadioButton2)
                    .addComponent(twoElevatorsCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(algRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(algRadioButton2)
                .addGap(18, 18, 18)
                .addComponent(twoElevatorsCheckbox)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        startButton.setText(resourceMap.getString("startButton.text")); // NOI18N
        startButton.setName("startButton"); // NOI18N
        startButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonActionPerformed(evt);
            }
        });

        stopButton.setText(resourceMap.getString("stopButton.text")); // NOI18N
        stopButton.setName("stopButton"); // NOI18N
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                .addComponent(floorCountSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(13, 13, 13))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(floorCountSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(startButton)
                    .addComponent(stopButton))
                .addContainerGap(68, Short.MAX_VALUE))
        );

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        passengerList.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("passengerList.border.title"))); // NOI18N
        passengerList.setModel(passengerListModel);
        passengerList.setName("passengerList"); // NOI18N
        jScrollPane1.setViewportView(passengerList);

        jPanel4.setName("jPanel4"); // NOI18N

        speedSlider.setMajorTickSpacing(2);
        speedSlider.setMaximum(9);
        speedSlider.setMinimum(1);
        speedSlider.setMinorTickSpacing(1);
        speedSlider.setPaintLabels(true);
        speedSlider.setPaintTicks(true);
        speedSlider.setSnapToTicks(true);
        speedSlider.setName("speedSlider"); // NOI18N
        speedSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                speedSliderStateChanged(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel5.border.title"))); // NOI18N
        jPanel5.setName("jPanel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        floorTimeSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(100)));
        floorTimeSpinner.setName("floorTimeSpinner"); // NOI18N
        floorTimeSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                floorTimeSpinnerStateChanged(evt);
            }
        });

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        enterTimeSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(100)));
        enterTimeSpinner.setName("enterTimeSpinner"); // NOI18N
        enterTimeSpinner.setValue(ENTER_TIME);
        enterTimeSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                enterTimeSpinnerStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(floorTimeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(jLabel6)))
                .addContainerGap(42, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel7)
                .addGap(33, 33, 33))
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addComponent(enterTimeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(68, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(floorTimeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(enterTimeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel6.border.title"))); // NOI18N
        jPanel6.setName("jPanel6"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        label1.setName("label1"); // NOI18N
        label1.setText(resourceMap.getString("label1.text")); // NOI18N

        label2.setName("label2"); // NOI18N
        label2.setText(resourceMap.getString("label2.text")); // NOI18N

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel14)
                    .addComponent(jLabel9)
                    .addComponent(jLabel15)
                    .addComponent(jLabel10)
                    .addComponent(jLabel16)
                    .addComponent(jLabel11)
                    .addComponent(jLabel17)
                    .addComponent(jLabel12)
                    .addComponent(jLabel18)
                    .addComponent(jLabel13)
                    .addComponent(jLabel19)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(153, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(55, 55, 55))
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addComponent(speedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(speedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        elevatorView.setName("elevatorView"); // NOI18N

        jScrollPane3.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jScrollPane3.border.title"))); // NOI18N
        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        logArea.setColumns(20);
        logArea.setEditable(false);
        logArea.setFont(resourceMap.getFont("logArea.font")); // NOI18N
        logArea.setLineWrap(true);
        logArea.setRows(5);
        logArea.setBorder(null);
        logArea.setName("logArea"); // NOI18N
        jScrollPane2.setViewportView(logArea);

        jScrollPane3.setViewportView(jScrollPane2);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(elevatorView, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE))
                .addGap(6, 6, 6)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(elevatorView, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane1)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)))
                .addGap(40, 40, 40))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N
        fileMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileMenuActionPerformed(evt);
            }
        });

        menuNewButton.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        menuNewButton.setText(resourceMap.getString("menuNewButton.text")); // NOI18N
        menuNewButton.setName("menuNewButton"); // NOI18N
        menuNewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuNewButtonActionPerformed(evt);
            }
        });
        fileMenu.add(menuNewButton);

        menuOpenButton.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        menuOpenButton.setText(resourceMap.getString("menuOpenButton.text")); // NOI18N
        menuOpenButton.setName("menuOpenButton"); // NOI18N
        menuOpenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuOpenButtonActionPerformed(evt);
            }
        });
        fileMenu.add(menuOpenButton);

        menuSaveButton.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        menuSaveButton.setText(resourceMap.getString("menuSaveButton.text")); // NOI18N
        menuSaveButton.setName("menuSaveButton"); // NOI18N
        menuSaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuSaveButtonActionPerformed(evt);
            }
        });
        fileMenu.add(menuSaveButton);

        menuDemoButton.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        menuDemoButton.setText(resourceMap.getString("menuDemoButton.text")); // NOI18N
        menuDemoButton.setName("menuDemoButton"); // NOI18N
        menuDemoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuDemoButtonActionPerformed(evt);
            }
        });
        fileMenu.add(menuDemoButton);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(symulatorwindy.SymulatorWindyApp.class).getContext().getActionMap(SymulatorWindyView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void floorCountSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_floorCountSpinnerStateChanged
        String ip = (String) floorCountSpinner.getValue().toString();
        int iloscPieter = Integer.parseInt(ip);
        w.SetIloscPieter(iloscPieter);
        newAnimation(iloscPieter);
        floor_count = iloscPieter;
    }//GEN-LAST:event_floorCountSpinnerStateChanged

    private void addPassengerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPassengerButtonActionPerformed
        String st = (String) startFloorSpinner.getValue().toString();
        String sp = (String) endFloorSpinner.getValue().toString();

        int start = Integer.parseInt(st);
        int stop = Integer.parseInt(sp);

        String ip = (String) multiplySpinner.getValue().toString();
            int ilePasazerow = Integer.parseInt(ip);
        if(ilePasazerow > 0){
            for(int i = 0; i < ilePasazerow; i++)
                w.AddPasazer(start, stop);
        }
        else{
            w.AddPasazer(start, stop);
        }
        addPassangerToList(start, stop);

        //startFloorSpinner.setValue(0);
        //endFloorSpinner.setValue(0);
        multiplySpinner.setValue(1);
        showPassengersOnFloors();
    }//GEN-LAST:event_addPassengerButtonActionPerformed

    private void removePassengerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePassengerButtonActionPerformed
        w.UsunOstatniegoPasazera();
        removeLastPassangerFromList();
        showPassengersOnFloors();
    }//GEN-LAST:event_removePassengerButtonActionPerformed

    private void speedSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_speedSliderStateChanged
        em.setSpeed(speedSlider.getValue());
    }//GEN-LAST:event_speedSliderStateChanged

    private void floorTimeSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_floorTimeSpinnerStateChanged
        String cj = (String) floorTimeSpinner.getValue().toString();
        int CzasJazdy = Integer.parseInt(cj);
        w.SetCzasJazdyPietro(CzasJazdy);
        em.setTimeForFloor(CzasJazdy);
        czasJazdyPrzezPietro = CzasJazdy;
    }//GEN-LAST:event_floorTimeSpinnerStateChanged

    private void enterTimeSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_enterTimeSpinnerStateChanged
        String cw = (String) enterTimeSpinner.getValue().toString();
        int czasWW = Integer.parseInt(cw);
        w.SetCzasWeWyOsoby(czasWW);
        czasWeWy = czasWW;
    }//GEN-LAST:event_enterTimeSpinnerStateChanged

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed
        if(!passengerListModel.isEmpty()){
            LOG.info("------------START--------------");
            w.Start();
            //setupAnimation();
            goToPietro();
            toggleComponents(false);
            stat();
        }

    }//GEN-LAST:event_startButtonActionPerformed

    private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
        em.stop();
        toggleComponents(true);
    }//GEN-LAST:event_stopButtonActionPerformed

    private void algRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_algRadioButton1ActionPerformed
        w.SetGoraDol();
        em.setStartFloors(0, floor_count-1);
        newAnimation(this.floor_count);
        showPassengersOnFloors();
    }//GEN-LAST:event_algRadioButton1ActionPerformed

    private void algRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_algRadioButton2ActionPerformed
        w.SetNajblizszeWzwanie();
        if(twoElevatorsCheckbox.isSelected()){
            em.setStartFloors(0, floor_count-1);
        }else
            em.setStartFloors(floor_count/2, 0);
        newAnimation(this.floor_count);
        showPassengersOnFloors();
    }//GEN-LAST:event_algRadioButton2ActionPerformed

    private void twoElevatorsCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_twoElevatorsCheckboxActionPerformed
        if(twoElevatorsCheckbox.isSelected()){
            em.enableSecondElevator();
            w.SetDwieWindy();
            if(w.getAlg() instanceof NajblizszeWezwanie){
                em.setStartFloors(0, floor_count-1);
            }
        }else{
            em.disableSecondElevator();
            w.SetJednaWindy();
            if(w.getAlg() instanceof NajblizszeWezwanie){
                em.setStartFloors(floor_count/2, 0);
            }
        }
        newAnimation(this.floor_count);
        showPassengersOnFloors();
    }//GEN-LAST:event_twoElevatorsCheckboxActionPerformed

    private void fileMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileMenuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_fileMenuActionPerformed

    private void menuNewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNewButtonActionPerformed
        newProject();
    }//GEN-LAST:event_menuNewButtonActionPerformed

    private void menuOpenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuOpenButtonActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        int choice = fileChooser.showOpenDialog(mainPanel);
        if(choice == JFileChooser.CANCEL_OPTION)
            return;
        File file = fileChooser.getSelectedFile();
        loadFile(file.getAbsolutePath());
        showPassengersOnFloors();
    }//GEN-LAST:event_menuOpenButtonActionPerformed

    private void menuSaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuSaveButtonActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        int choice = fileChooser.showSaveDialog(mainPanel);
        if(choice == JFileChooser.CANCEL_OPTION)
            return;
        File file = fileChooser.getSelectedFile();
        writeToFile(file);
    }//GEN-LAST:event_menuSaveButtonActionPerformed

    private void menuDemoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDemoButtonActionPerformed
        loadFile("DemoDane.txt");
        showPassengersOnFloors();
    }//GEN-LAST:event_menuDemoButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addPassengerButton;
    private javax.swing.JRadioButton algRadioButton1;
    private javax.swing.JRadioButton algRadioButton2;
    private java.awt.ScrollPane elevatorView;
    private javax.swing.JSpinner endFloorSpinner;
    private javax.swing.JSpinner enterTimeSpinner;
    private javax.swing.JSpinner floorCountSpinner;
    private javax.swing.JSpinner floorTimeSpinner;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private java.awt.Label label1;
    private java.awt.Label label2;
    private javax.swing.JTextArea logArea;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem menuDemoButton;
    private javax.swing.JMenuItem menuNewButton;
    private javax.swing.JMenuItem menuOpenButton;
    private javax.swing.JMenuItem menuSaveButton;
    private javax.swing.JSpinner multiplySpinner;
    private javax.swing.JList passengerList;
    private javax.swing.JButton removePassengerButton;
    private javax.swing.JSlider speedSlider;
    private javax.swing.JButton startButton;
    private javax.swing.JSpinner startFloorSpinner;
    private javax.swing.JButton stopButton;
    private javax.swing.JCheckBox twoElevatorsCheckbox;
    // End of variables declaration//GEN-END:variables


    private JDialog aboutBox;

    class Refresh extends Thread{
    public Refresh(ScrollPane sc){
            this.scrollPane = sc;
    }

    
    ScrollPane scrollPane;

    @Override
    public void run(){
        jLabel8.setText("Minimalny czas obsługi pasażera:");
        jLabel9.setText("Maxymalny czas obsługi pasażera:");
        jLabel10.setText("Średni czas obsługi pasażera:");
        jLabel11.setText("Minimalnz czas czekania:");
        jLabel12.setText("Maxymalny czas czekania:");
        jLabel13.setText("Średni czas czekania:");
        label1.setText("Liczba osobo pięter:");
        while(true){
            try {
                sleep(20);
                this.scrollPane.repaint();
            } catch (InterruptedException ex) {
                Logger.getLogger(Refresh.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }
}
}
